<?php
include("include/conn.php");
require('include/Smarty/libs/Smarty.class.php');
$party   = array();
$veepari = array();
$veepariId = 0;

if(isset($_POST['party']) && $_POST['party'] > 0)
{
  $weight   = ($_POST['weight'] != '') ? $_POST['weight'] : 0;
  $touch    = ($_POST['touch'] != '') ? $_POST['touch'] : 0;
  $fine     = ($_POST['fine'] != '') ? $_POST['fine'] : 0;
  $amount   = ($_POST['amount'] != '') ? $_POST['amount'] : 0;
  if($_POST['veepariId'] > 0)
  {
    $updateVeepariBook = "UPDATE vepaaribook SET partyId = ".$_POST['party'].", vepaariBookDate = '".$_POST['curDateYear']."-".$_POST['curDateMonth']."-".$_POST['curDateDay']."', particulars = '".$_POST['particulars']."', weight = ".$weight.", touch = ".$touch.", fine = ".$fine.", amount = ".$amount.", CrDr = '".$_POST['crdr']."'
                                WHERE vepaaribookId = ".$_GET['vepaaribookId'];
    $updateVeepariBookRes = mysql_query($updateVeepariBook);
    
    header("location:vepaariBookDetail.php");
  }
  else
  {
    $insetVeepariBook = "INSERT INTO vepaaribook (partyId,vepaariBookDate,particulars,weight,touch,fine,amount,CrDr)
                         VALUES (".$_POST['party'].",'".$_POST['curDateYear']."-".$_POST['curDateMonth']."-".$_POST['curDateDay']."','".$_POST['particulars']."',
                                 ".$weight.",".$touch.",".$fine.",".$amount.",'".$_POST['crdr']."')";
    $insetVeepariBookRes = mysql_query($insetVeepariBook);
  }
}

if(isset($_GET['vepaaribookId']))
{
  $veepariBook = "SELECT vepaaribookId,partyId,vepaariBookDate,particulars,weight,touch,fine,amount,CrDr FROM vepaaribook
                   WHERE vepaaribookId = ".$_GET['vepaaribookId'];
  $veepariBookRes = mysql_query($veepariBook);
  $a = 0;
  if($veepariRow = mysql_fetch_assoc($veepariBookRes))
  {
    $veepariId                  = $_GET['vepaaribookId'];
    $veepari['partyId']         = $veepariRow['partyId'];
    $veepari['vepaariBookDate'] = $veepariRow['vepaariBookDate'];
    $veepari['particulars']     = $veepariRow['particulars'];
    $veepari['weight']          = $veepariRow['weight'];
    $veepari['touch']           = $veepariRow['touch'];
    $veepari['fine']            = $veepariRow['fine'];
    $veepari['amount']          = $veepariRow['amount'];
    $veepari['CrDr']            = $veepariRow['CrDr'];
    $a++;
  }
}

$selectParty = "SELECT partyId,partyName 
                  FROM party
                 ORDER BY partyName";
$selectPartyRes = mysql_query($selectParty);
$a = 0;
$party['partyId'][$a]   = 0;
$party['partyName'][$a] = "Select";
$a++;
while($partyRow = mysql_fetch_assoc($selectPartyRes))
{
  $party['partyId'][$a]   = $partyRow['partyId'];
  $party['partyName'][$a] = $partyRow['partyName'];
  $a++;
}

$smarty = new Smarty;
require("bottom.php");

$smarty->assign("l_partySelect",$l_partySelect);
$smarty->assign("l_date",$l_date);
$smarty->assign("l_particulars",$l_particulars);
$smarty->assign("l_weight",$l_weight);
$smarty->assign("l_touch",$l_touch);
$smarty->assign("l_fine",$l_fine);
$smarty->assign("l_amount",$l_amount);
$smarty->assign("l_add",$l_add);
$smarty->assign("l_cancel",$l_cancel);
$smarty->assign("l_credit",$l_credit);
$smarty->assign("l_debit",$l_debit);
$smarty->assign("l_save",$l_save);

$smarty->assign("party",$party);
$smarty->assign("veepari",$veepari);
$smarty->assign("veepariId",$veepariId);

$smarty->display("vepaariBook.tpl");
?>